package org.example;


import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
       // Test01();
       Test02();
    }

    private static void Test02() throws IOException {
        WebDriver webDriver  =new ChromeDriver();
        webDriver.get("https://www.baidu.com");
        File file = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(file,new File("D://截图2024_3_31.png"));
        webDriver.quit();
    }

    private static void Test01() {
        WebDriver webDriver  =new ChromeDriver();
        webDriver.get("https://www.baidu.com");
        if( webDriver.findElement(By.cssSelector("#kw"))==null){
            System.out.println("测试不通过");
        }else{
            System.out.println("测试通过");
        }
        if( webDriver.findElement(By.xpath("//*[@id=\"kw\"]"))==null){
            System.out.println("测试不通过");
        }else{
            System.out.println("测试通过");
        }
    }
}